package cn.dujc.superkid.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dujc.superkid.R;
import cn.dujc.superkid.bean.UnitResult;

/**
 * Created by Administrator on 2018/10/16 0016.
 */

public class UnitTestLegendAdapter extends RecyclerView.Adapter<UnitTestLegendAdapter.ViewHolder> {
    private Context context;
    private List<UnitResult.DataBean.ScoreStatisticsBean>datas;

    public void setDatas(List<UnitResult.DataBean.ScoreStatisticsBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    public UnitTestLegendAdapter(Context context) {
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_unittest_result_legend,null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.colorView.setBackgroundColor(Color.parseColor(datas.get(position).getColor()));
        holder.contentText.setText(datas.get(position).getGroup_name()+""+datas.get(position).getScore()+"%");
    }

    @Override
    public int getItemCount() {
        return datas==null?0:datas.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        View colorView;
        TextView contentText;
        public ViewHolder(View itemView) {
            super(itemView);
            colorView=itemView.findViewById(R.id.item_unitest_result_legend_color);
            contentText=itemView.findViewById(R.id.item_unitest_result_legend_text);
        }
    }
}
